<template>
    <div class="app" style="margin-bottom: 10px">
        <!-- 上传 -->
        <el-form :inline="true" ref="form" label-width="120px">
            <el-form-item label="" prop="accessory">
                <el-upload class="upload-demo" :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" :multiple="multiple" :before-upload="beforeUpload" :on-exceed="handleExceed" :action="uploadApi" :show-file-list="orderData" :headers="{ Authorization: authToken }" :on-success="accessory">
                    <el-button size="small" type="primary" v-if="hidden == false">选择文件</el-button>
                </el-upload>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import { getToken } from "@/utils/auth";
export default {
    name: "Firetruck",
    props: {
        orderData: {
            type: Boolean,
            default: false,
        },
        hidden: {
            default: false,
        },
        multiple: {
            default: true,
        },
    },
    data() {
        return {
            //上传
            // fileListaa: [],
        };
    },
    created() {},
    computed: {
        uploadApi() {
            return process.env.VUE_APP_BASE_API + "/com/ComAttach";
        },
        authToken() {
            return "Bearer " + getToken();
        },
    },

    methods: {
        // 上传
        handleRemove(file, fileList) {},
        handlePreview(file) {},
        handleExceed(files, fileList) {
            this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
        },
        beforeRemove(file, fileList) {
            return this.$confirm(`确定移除 ${file.name}？`);
        },

        accessory(response, file, fileList) {
            this.$modal.closeLoading();
            if (response.code == 200) {
                this.$emit("uploading", response.data);
            } else {
                this.$modal.msgError(response.msg);
            }
        },
        beforeUpload() {
            this.$modal.loading("正在上传中...");
        },
    },
};
</script>
<style scoped></style>
